<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="主机编号" prop="hostEncoding">
        <el-input
          v-model="queryParams.hostEncoding"
          placeholder="请输入主机编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据中心" prop="dataCenter">
        <el-input
          v-model="queryParams.dataCenter"
          placeholder="请输入数据中心"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="容量使用情况" prop="capacityUsage">
        <el-input
          v-model="queryParams.capacityUsage"
          placeholder="请输入容量使用情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务运行状况" prop="healthStatus">
        <el-select v-model="queryParams.healthStatus" placeholder="请选择任务运行状况" clearable>
          <el-option
            v-for="dict in dict.type.status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="告警统计" prop="alarmStatistics">
        <el-input
          v-model="queryParams.alarmStatistics"
          placeholder="请输入告警统计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属省市" prop="provinceAndCity">
        <el-input
          v-model="queryParams.provinceAndCity"
          placeholder="请输入所属省市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日志" prop="log">
        <el-input
          v-model="queryParams.log"
          placeholder="请输入日志"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备份" prop="backup">
        <el-input
          v-model="queryParams.backup"
          placeholder="请输入备份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:management:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:management:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:management:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:management:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="managementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="主机编号" align="center" prop="hostEncoding" />
      <el-table-column label="数据中心" align="center" prop="dataCenter">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.data_center" :value="scope.row.dataCenter"/>
        </template>
      </el-table-column>
      <el-table-column label="容量使用情况" align="center" prop="capacityUsage" />
      <el-table-column label="任务运行状况" align="center" prop="healthStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.status" :value="scope.row.healthStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="告警统计" align="center" prop="alarmStatistics" />
      <el-table-column label="所属省市" align="center" prop="provinceAndCity" />
      <el-table-column label="日志" align="center" prop="log" />
      <el-table-column label="备份" align="center" prop="backup" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:management:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:management:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="42%" append-to-body>
        <div style="height: 500px;overflow: auto;">
      <el-form ref="form" :inline="true" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="主机编号" prop="hostEncoding">
          <el-input v-model="form.hostEncoding" placeholder="请输入主机编号" />
        </el-form-item>
        <el-form-item label="数据中心" prop="dataCenter">
          <el-input v-model="form.dataCenter" placeholder="请输入数据中心" />
        </el-form-item>
        <el-form-item label="容量使用情况" prop="capacityUsage">
          <el-input v-model="form.capacityUsage" placeholder="请输入容量使用情况" />
        </el-form-item>
        <el-form-item label="任务运行状况" prop="healthStatus">
          <el-radio-group v-model="form.healthStatus">
            <el-radio
              v-for="dict in dict.type.status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="告警统计" prop="alarmStatistics">
          <el-input v-model="form.alarmStatistics" placeholder="请输入告警统计" />
        </el-form-item>
        <el-form-item label="所属省市" prop="provinceAndCity">
          <el-input v-model="form.provinceAndCity" placeholder="请输入所属省市" />
        </el-form-item>
        <el-form-item label="日志" prop="log">
          <el-input v-model="form.log" placeholder="请输入日志" />
        </el-form-item>
        <el-form-item label="备份" prop="backup">
          <el-input v-model="form.backup" placeholder="请输入备份" />
        </el-form-item>
        <el-form-item label="是否删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入是否删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="扩展1" prop="extend1">
          <el-input v-model="form.extend1" placeholder="请输入扩展1" />
        </el-form-item>
        <el-form-item label="扩展2" prop="extend2">
          <el-input v-model="form.extend2" placeholder="请输入扩展2" />
        </el-form-item>
        <el-form-item label="扩展3" prop="extend3">
          <el-input v-model="form.extend3" placeholder="请输入扩展3" />
        </el-form-item>
        <el-form-item label="扩展4" prop="extend4">
          <el-input v-model="form.extend4" placeholder="请输入扩展4" />
        </el-form-item>
        <el-form-item label="扩展5" prop="extend5">
          <el-input v-model="form.extend5" placeholder="请输入扩展5" />
        </el-form-item>
        <el-form-item label="扩展6" prop="extend6">
          <el-input v-model="form.extend6" placeholder="请输入扩展6" />
        </el-form-item>
        <el-form-item label="扩展7" prop="extend7">
          <el-input v-model="form.extend7" placeholder="请输入扩展7" />
        </el-form-item>
        <el-form-item label="扩展8" prop="extend8">
          <el-input v-model="form.extend8" placeholder="请输入扩展8" />
        </el-form-item>
        <el-form-item label="扩展9" prop="extend9">
          <el-input v-model="form.extend9" placeholder="请输入扩展9" />
        </el-form-item>
        <el-form-item label="扩展10" prop="extend10">
          <el-input v-model="form.extend10" placeholder="请输入扩展10" />
        </el-form-item>
      </el-form>
        </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listManagement, getManagement, delManagement, addManagement, updateManagement } from "@/api/system/management";

export default {
  name: "Management",
  dicts: ['status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 管理表格数据
      managementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hostEncoding: null,
        dataCenter: null,
        capacityUsage: null,
        healthStatus: null,
        alarmStatistics: null,
        provinceAndCity: null,
        log: null,
        backup: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询管理列表 */
    getList() {
      this.loading = true;
      listManagement(this.queryParams).then(response => {
        this.managementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        hostEncoding: null,
        dataCenter: null,
        capacityUsage: null,
        healthStatus: null,
        alarmStatistics: null,
        provinceAndCity: null,
        log: null,
        backup: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        extend1: null,
        extend2: null,
        extend3: null,
        extend4: null,
        extend5: null,
        extend6: null,
        extend7: null,
        extend8: null,
        extend9: null,
        extend10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getManagement(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateManagement(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addManagement(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除管理编号为"' + ids + '"的数据项？').then(function() {
        return delManagement(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/management/export', {
        ...this.queryParams
      }, `management_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
